﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dqs_BLL;
using Dqs_DAL;
using Model;
using Sunny.UI;

namespace Dqs_UI
{
	public partial class frmUpdateCourse : UIForm
	{
		public frmUpdateCourse(int id)
		{
			InitializeComponent();
			this.Id = id;
		}

		Course_BLL course_BLL = new Course_BLL();
		Teacher_BLL teacher_BLL = new Teacher_BLL();
		Class_BLL class_BLL = new Class_BLL();
		int Id { get; set; }

		/// <summary>
		/// 重置
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void uiButton2_Click(object sender, EventArgs e)
		{
			frmUpdateCourse_Load(this, e);
		}

		private void frmUpdateCourse_Load(object sender, EventArgs e)
		{
			//加载数据
			CourseInfo courseInfo = course_BLL.GetCourses().Where(a => a.Id == Id).FirstOrDefault()!;
			txtCourseName.Text = courseInfo.CourseName;
			txtDescription.Text = courseInfo.Description;
			txtEndTime.Text = courseInfo.EndTime.ToString();
			txtStartTime.Text = courseInfo.StartTime.ToString();

		}

		/// <summary>
		/// 确定更新
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void uiButton1_Click(object sender, EventArgs e)
		{
			CourseInfo courseInfo = new CourseInfo();
			courseInfo.Id = Id;
			courseInfo.StartTime = Convert.ToDateTime(txtStartTime.Text.Trim());
			courseInfo.EndTime = Convert.ToDateTime(txtEndTime.Text.Trim());
			courseInfo.CourseName = txtCourseName.Text.Trim();
			courseInfo.Description = txtDescription.Text.Trim();
			
			if (course_BLL.UpdateCourseInfoById(courseInfo))
			{
				DialogResult = DialogResult.OK;
			}
			else
			{
				MessageBox.Show("请检查输入内容是否正确！");
			}

		}

		private void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
		{

		}
	}
}
